<template>
  <div o-Container>
    <o-list v-bind:source="list.contract" v-bind="{ created: create, exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="showLookDiaolog(scope)"
            src="../../../../../static/skin/default/MCS/AIGC/Inventory/images/chakan.png" alt="">
            <img @click="showEditDialog(scope)"
            src="../../../../../static/skin/default/MCS/AIGC/Inventory/images/bianji.png" alt="">
        </div>
      </template>
    </o-list>
    <CatMsg ref="CatMsg" :messageList="messageList"></CatMsg>
    <EditCat ref="EditCat" :type="dialogType" :messageList="messageListAdd" @refresh="refresh"></EditCat>
  </div>
</template>

<script>
import CatMsg from '../Components/CatMsg.vue'
import EditCat from '../Components/EditCat.vue'
export default {
  components: {
    CatMsg,
    EditCat,
  },
  name: "mms_platform_company_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1231, // 菜单表的八爪鱼ID
            cellData: [
              {name: "Code"},	// 车牌
              {name: "BrandID", show: false},	// 车品牌
              {name: "BrandIDName"},	// 车品牌
              {name: "SystemID", show: false},	// 车系
              {name: "SystemIDName"},	// 车系
              {name: "TypeID", show: false},	// 车型
              {name: "TypeIDName"},	// 车型
              {name: "CreateUserID", show: false},	// 创建人
              {name: "CreateUserIDName"},
              {name: "CreateTime", width: 200},	// 创建时间
            ],
            paramData: {}
          },
          configWidth: 60,
          showNumber: true,
        },
      },
      messageList: {},
      messageListAdd: {},
      dialogType: 2,
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      const data = this.list.contract.data;
      const company = this.octopus.passport.authorization.company
      data.paramData.CompanyID = company == 1 ? 'NULL' : company
    },
    showLookDiaolog(row) {
      this.messageList = row.data.row
      this.$refs.CatMsg.drawerOp()
    },
    showEditDialog(row) {
      this.dialogType = 2
      let o = this
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1231,
          cellData: [
            {name: "ID"},	// ID
            {name: "Code", filterKey: "=", filterValue: row.data.row.Code},	// 车牌
            {name: "BrandID"},	// 车品牌
            {name: "SystemID"},	// 车系
            {name: "TypeID"},	// 车型
            {name: "CreateUserID"},	// 创建人
            {name: "CreateTime"},	// 创建时间
          ],
          paramData: {
            CompanyID: this.octopus.passport.authorization.company == 1 ? "NULL" :this.octopus.passport.authorization.company,
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.messageListAdd = data.content.queryData[0]
            o.$refs.EditCat.drawerOp()
          } else {
            o.octopus.tips.error(data);
          }
        });
    },
    output: function (data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function (cell) {
    },
    create: function (data) {
      this.dialogType = 1
      this.messageListAdd = {}
      this.$refs.EditCat.drawerOp()
    },
    save: function (data) {// 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function () {
      this.panel.visible = false;
    },
    del: function (row) {
      let o = this
      // alert("del key: " + JSON.stringify(row));
      this.$confirm('此操作将永久删除该项, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.octopus.request.api.post("/Octopus/Engine/Item", {
          id: 1188, // 菜单表的八爪鱼ID
          type: "DELETE",
          value: row.ID,
          cellData: [
            { name: "ID", defaultValue: row.ID },
          ],
        },
          // 处理回调事件，通过分析data.status.code的状态来实现。
          function (data) {
            if (data.status.code === 200) {
              o.list.contract.control.load();
            } else {
              o.octopus.tips.error(data);
            }
          }
        );
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    refresh() {
      this.list.contract.control.load();
    },
    lookRow(index, rows) {
      this.$refs.MessageDialog.drawerOp()
    },
  },
  props: ["oData"]
}
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}
</style>
